package net.lzzy.tapDemo;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

import java.util.List;

public class TapSortBy {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setAppName("TapSortBy").setMaster(args[0]);
        JavaSparkContext javaSparkContext = new JavaSparkContext(conf);
        JavaRDD<String> javaRDD = javaSparkContext.textFile("E:\\Spark\\testDemo\\violation.txt");
        JavaRDD<String> javaRDD1 = javaRDD.sortBy(v1->
                Integer.parseInt(v1.split("\t")[1]), false, javaRDD.getNumPartitions());
        List<String> collect1 = javaRDD1.collect();
        for (String s : collect1) {
            System.out.println(s);
        }
        List<String> collect = javaRDD1.take(3);
        for (String s : collect) {
            System.out.println(s);
        }
    }
}
